package com.ebt.m.customer.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;

import com.ebt.m.R;
import com.ebt.m.customer.model.CustomerModelNew;
import com.ebt.m.customer.ui.ActivityCustomerActive;
import com.ebt.m.customer.ui.ActivityCustomerPolicy;
import com.jakewharton.rxbinding2.view.RxView;

import java.util.concurrent.TimeUnit;

/**
 * 30天活动客户和保单客户的view
 */
public class CustomerItemMainActiveView extends FrameLayout implements ICustomizedViewNew {
    private View contentView;
    private int from;

    public CustomerItemMainActiveView(Context context, int from) {
        this(context);
        this.from = from;
    }

    public CustomerItemMainActiveView(Context context) {
        this(context, null);
    }

    public CustomerItemMainActiveView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomerItemMainActiveView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        contentView = inflate(context, R.layout.view_customer_item_main_active, this);
        RxView.clicks(contentView.findViewById(R.id.rl_item_view_30))
                .throttleFirst(500, TimeUnit.MILLISECONDS)
                .subscribe(aVoid -> {
                    Intent intent = new Intent(getContext(), ActivityCustomerActive.class);
                    intent.putExtra("from", from);
                    getContext().startActivity(intent);
                    ((Activity) getContext()).overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);
                });
        RxView.clicks(contentView.findViewById(R.id.rl_item_view_policy))
                .throttleFirst(500, TimeUnit.MILLISECONDS)
                .subscribe(aVoid -> {
                    Intent intent = new Intent(getContext(), ActivityCustomerPolicy.class);
                    intent.putExtra("from", from);
                    getContext().startActivity(intent);
                    ((Activity) getContext()).overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);
                });
    }


    @Override
    public View getView() {
        return this;
    }

    @Override
    public void update(CustomerModelNew model) {
    }

    @Override
    public void showSortTitle(String sortTitle) {

    }
}